package svc

import (
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"web_server/internal/config"
	"web_server/internal/model"
)

type MysqlModels struct {
	OneSayModel      model.OneSayModel
	BingImageModel   model.BingImageModel
	WordsModel       model.WordsModel
	ShortPoetryModel model.ShortPoetryModel
	PoetryModel      model.PoetryModel
	PoetModel        model.PoetModel
}

func ConnectMysql(c config.MySql) MysqlModels {
	var dsn string = fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", c.User, c.Password, c.Host, c.Port, c.Database)
	conn := sqlx.NewMysql(dsn)

	return MysqlModels{
		OneSayModel:      model.NewOneSayModel(conn),
		BingImageModel:   model.NewBingImageModel(conn),
		WordsModel:       model.NewWordsModel(conn),
		ShortPoetryModel: model.NewShortPoetryModel(conn),
		PoetryModel:      model.NewPoetryModel(conn),
		PoetModel:        model.NewPoetModel(conn),
	}
}
